<?php
// leetcode 71题简化路径
class Solution {

    /**
     * @param String $path
     * @return String
     */
    function simplifyPath($path) {
        $arr = preg_split("#/#", $path);
        $stk = [];
        foreach ($arr as $value) {
            if (!in_array($value, ['', '.', '..'])) {
                $stk[] = $value;
            } else if ($value == '..' && $stk) {
                array_pop($stk);
            }
        }
        return '/' . implode('/', $stk);
    }
}
$solution = new Solution();
//$path = "/a/./b/../../c/";
$path = "/home/";
$res = $solution->simplifyPath($path);
echo $res;